/**
 * @description 用户信息校验
 * @author 宫彦胜
 */

// 引入中间处理
const validate = require('./_validate')

// 定义一套规则
const SCHEMA = {
  type: 'object',
  properties: {
    userName: {
      type: 'string',
      pattern: '^[A-Za-z][a-zA-Z0-9_]+$', // 一段儿正则， 字母开头，数字下划线结束
      maxLength: 15,
      minLength: 6,
      description: '账号必须是以下字母开头，6-15位之间'

    },
    password: {
      type: 'string',
      maxLength: 15,
      minLength: 6,
      description: '密码校验失败'
    },
    newPassword: {
      type: 'string',
      maxLength: 15,
      minLength: 6
    },
    nickName: {
      type: 'string',
      maxLength: 15
    },
    picture: {
      type: 'string',
      maxLength: 255
    },
    city: {
      type: 'string',
      maxLength: 25,
      minLength: 2
    },
    gender: {
      type: 'number',
      minimum: 1,
      maximum: 3
    }
  },
  
}

/**
 * 
 * @param {object} data 要验证的用户数据 
 */
function userValidate(data = {}){
  return validate(SCHEMA, data)
}


module.exports = userValidate
